package com.example.demo.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;


@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name="user")
public class User implements UserDetails {

    @Id
    @Column(name="id",length=20,nullable=false)
    private String ID;

    @Column(name="identityid",length=20,nullable=false)
    private String identityId;

    @Column(name="name",length=20,nullable=false)
    private String name;

    @Column(name="password",length=50)
    private String password;

    @Column(name="phonenumber",length=20,nullable=true)
    private String phoneNumber;

    @Column(name="mail",length=100,nullable=true)
    private String mail;

    @Column(name="role",nullable=false)
    private String role;

    @Column(name="firstlogin")
    private Integer firstLogin = 0;

    @Column(name="token")
    private String token;

    @Column(name="umajor")
    private String umajor;

    @Column(name="uschool")
    private String uschool;

    @Column(name="ustatus")
    private String ustatus;

    @OneToMany(targetEntity = Course.class,mappedBy ="teacher", cascade = CascadeType.ALL)
    private List<Course> courses;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.name;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


}
